#include "manage.h"
#include "RecordTimeDormDialog.h"
#include <QVBoxLayout>
#include <QLabel>

Manage::Manage(QWidget* parent)
    : QWidget(parent), ui(new Ui::ManageClass)
{
    ui->setupUi(this);
    resize(800, 600);
    setWindowTitle(tr("Student Manage System"));

    // 初始化按钮
    closeButton = new QPushButton(tr("Exit"), this);
    closeButton->setFixedSize(150, 100);
    closeButton->move(320, 380);
    closeButton->setStyleSheet("QPushButton { background-color : white; color : black; font : 30px; }");

    adminButton = new QPushButton(tr("Admin"), this);
    adminButton->setFixedSize(150, 100);
    adminButton->move(320, 120);
    adminButton->setStyleSheet("QPushButton { background-color : white; color : black; font : 30px; }");

    stuButton = new QPushButton(tr("Student"), this);
    stuButton->setFixedSize(150, 100);
    stuButton->move(320, 250);
    stuButton->setStyleSheet("QPushButton { background-color : white; color : black; font : 30px; }");

    // 初始化部件
    stackedWidget = new QStackedWidget(this);
    mainPage = new QWidget(this);
    adminPage = new AdminWindow(this);
    stuPage = new StuWindow(this);

    QVBoxLayout* mainLayout = new QVBoxLayout(mainPage);
    mainLayout->addWidget(adminButton);
    mainLayout->addWidget(stuButton);
    mainLayout->addWidget(closeButton);

    stackedWidget->addWidget(mainPage);
    stackedWidget->addWidget(adminPage);
    stackedWidget->addWidget(stuPage);

    QVBoxLayout* layout = new QVBoxLayout(this);
    layout->addWidget(stackedWidget);

    stackedWidget->setCurrentWidget(mainPage);

    // 连接主菜单按钮
    connect(closeButton, &QPushButton::clicked, this, &Manage::close);
    connect(adminButton, &QPushButton::clicked, this, &Manage::open_admin);
    connect(stuButton, &QPushButton::clicked, this, &Manage::open_student);
}

Manage::~Manage()
{
    delete ui;
}

void Manage::open_admin()
{
    stackedWidget->setCurrentWidget(adminPage);
}

void Manage::open_student()
{
    stackedWidget->setCurrentWidget(stuPage);
}

void Manage::return_to_main()
{
    stackedWidget->setCurrentWidget(mainPage);
}

AdminWindow::AdminWindow(QWidget* parent)
    : QWidget(parent)
{
    QVBoxLayout* layout = new QVBoxLayout(this);
    resize(800, 600);
    setWindowTitle(tr("AdminPage"));

    // 返回按钮
    returnButton = new QPushButton(tr("Return"), this);
    layout->addWidget(returnButton);

    // 初始化管理页面按钮
    recordTimeDormButton = new QPushButton(tr("Record Time and Dorm Info"), this);
    recordCheckinStudentButton = new QPushButton(tr("Record Check-in Student Info"), this);
    recordCheckinReminderButton = new QPushButton(tr("Record Check-in Reminder"), this);
    updateInfoButton = new QPushButton(tr("Update Info"), this);
    queryDisplayInfoButton = new QPushButton(tr("Query and Display Info"), this);
    deleteInfoButton = new QPushButton(tr("Delete Info"), this);
    queryCheckinApplicationButton = new QPushButton(tr("Query Check-in Application"), this);

    layout->addWidget(recordTimeDormButton);
    layout->addWidget(recordCheckinStudentButton);
    layout->addWidget(recordCheckinReminderButton);
    layout->addWidget(updateInfoButton);
    layout->addWidget(queryDisplayInfoButton);
    layout->addWidget(deleteInfoButton);
    layout->addWidget(queryCheckinApplicationButton);

    // 连接按钮
    connect(returnButton, &QPushButton::clicked, [parent]() { static_cast<Manage*>(parent)->return_to_main(); });
    connect(recordTimeDormButton, &QPushButton::clicked, this, &AdminWindow::record_time_dorm_info);
    connect(recordCheckinStudentButton, &QPushButton::clicked, this, &AdminWindow::record_checkin_student_info);
    connect(recordCheckinReminderButton, &QPushButton::clicked, this, &AdminWindow::record_checkin_reminder);
    connect(updateInfoButton, &QPushButton::clicked, this, &AdminWindow::update_info);
    connect(queryDisplayInfoButton, &QPushButton::clicked, this, &AdminWindow::query_display_info);
    connect(deleteInfoButton, &QPushButton::clicked, this, &AdminWindow::delete_info);
    connect(queryCheckinApplicationButton, &QPushButton::clicked, this, &AdminWindow::query_checkin_application);
}

void AdminWindow::record_time_dorm_info()
{
    RecordTimeDormDialog dialog(this);
    dialog.exec();
}

void AdminWindow::record_checkin_student_info()
{
    // 在此添加点击后的执行的操作
}

void AdminWindow::record_checkin_reminder()
{
    // 在此添加点击后的执行的操作
}

void AdminWindow::update_info()
{
    // 在此添加点击后的执行的操作
}

void AdminWindow::query_display_info()
{
    // 在此添加点击后的执行的操作
}

void AdminWindow::delete_info()
{
    // 在此添加点击后的执行的操作
}

void AdminWindow::query_checkin_application()
{
    // 在此添加点击后的执行的操作
}

StuWindow::StuWindow(QWidget* parent)
    : QWidget(parent)
{
    QVBoxLayout* layout = new QVBoxLayout(this);
    resize(800, 600);
    setWindowTitle(tr("StudentPage"));

    // 返回按钮
    returnButton = new QPushButton(tr("Return"), this);
    layout->addWidget(returnButton);

    // 学生页面按钮
    submitApplicationButton = new QPushButton(tr("Submit Application"), this);
    recordCheckinButton = new QPushButton(tr("Record Check-in Information"), this);
    queryDisplayCheckinButton = new QPushButton(tr("Query and Display Check-in Information"), this);

    layout->addWidget(submitApplicationButton);
    layout->addWidget(recordCheckinButton);
    layout->addWidget(queryDisplayCheckinButton);

    // 连接按钮
    connect(returnButton, &QPushButton::clicked, [parent]() { static_cast<Manage*>(parent)->return_to_main(); });
    connect(submitApplicationButton, &QPushButton::clicked, this, &StuWindow::submit_application);
    connect(recordCheckinButton, &QPushButton::clicked, this, &StuWindow::record_checkin);
    connect(queryDisplayCheckinButton, &QPushButton::clicked, this, &StuWindow::query_display_checkin);
}

void StuWindow::submit_application()
{
    // 在此添加点击后的执行的操作
}

void StuWindow::record_checkin()
{
    // 在此添加点击后的执行的操作
}

void StuWindow::query_display_checkin()
{
    // 在此添加点击后的执行的操作
}